package com.longge;

import java.util.Arrays;

public class CloseStrings {

    public boolean closeStrings(String word1, String word2) {

        int[] count1 = new int[26];
        int[] count2 = new int[26];
        char[] chars1 = word1.toCharArray();
        char[] chars2 = word2.toCharArray();

        for (int i = 0; i < chars1.length; i++) {
            count1[chars1[i]-'a']++;
        }
        for (int i = 0; i < chars2.length; i++) {
            count2[chars2[i]-'a']++;
        }
        for (int i = 0; i <26 ; i++) {
            if ((count1[i]==0&&count2[i]!=0)||(count2[i]==0&&count1[i]!=0)) return false;
        }
        Arrays.sort(count1);
        Arrays.sort(count2);
        return Arrays.equals(count1, count2);
    }
}
